package weaver.interfaces.cese.duss.service.impl;

import com.alibaba.fastjson.JSONObject;
import weaver.general.BaseBean;
import weaver.general.Util;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

import static com.engine.cese.duss.tianyancha.util.HttpClientUtil.sendGetHttpRequest;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2020-11-18
 * @Description: 工商基本信息接口
 * @ModifyLog:
 **/
@WebServlet("/tianyancha/businessInfo")
public class BusinessInfoServiceImpl extends HttpServlet {
    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        super.doPost( req, res );
    }

    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        String keyword = Util.null2String( req.getParameter("keyword"));
        PrintWriter out = res.getWriter();
        BaseBean baseBean = new BaseBean();
        res.setHeader("Content-type", "text/html;charset=UTF-8");
        try {
            String url  = baseBean.getPropValue("tianyancha","url");
            String TOKEN = baseBean.getPropValue("tianyancha","token");
            String URL = url+"?keyword="+keyword;
            String URLCode = "UTF-8";
            JSONObject resultJson = sendGetHttpRequest(URL,TOKEN,URLCode);
            out.print(resultJson.toJSONString());
        } catch (Exception e) {
            e.printStackTrace();
            out.print("request error");
        }
    }
}
